package com.fengzuxiao.weatherdemo.lr;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.fengzuxiao.weatherdemo.R;
import com.fengzuxiao.weatherdemo.User;
import com.fengzuxiao.weatherdemo.UserService;

import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by 17929 on 2020/6/17.
 */

public class ChangeActivity  extends AppCompatActivity implements View.OnClickListener{
    private EditText edit_3,edit_4,edit_5;
    private Button change;

    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change);
        init();
    }

    private void init() {
        edit_3= findViewById(R.id.edt_3);
        edit_4= findViewById(R.id.edt_4);
        edit_5= findViewById(R.id.edt_5);
        change= findViewById(R.id.change);
        change.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        String psw=edit_3.getText().toString().trim();
        String cpsw=edit_4.getText().toString().trim();
        String uname=edit_5.getText().toString().trim();
        UserService uService= new  UserService(this);
        User user=new User();
        user.setUsername(uname);
        user.setPassword(psw);
        user.setPassword(cpsw);
        boolean fals=uService.update(user);
        if (TextUtils.isEmpty(psw)&&TextUtils.isEmpty(cpsw)&&TextUtils.isEmpty(uname)){
            Toast.makeText(this, "不能为空", Toast.LENGTH_SHORT).show();
        } else if (psw.equals(cpsw)){
            Toast.makeText(this, "原密码与新密码不能一致", Toast.LENGTH_SHORT).show();
        } else if (fals){
            onBackPressed();
            Log.i("TAG","222");
            Toast.makeText(this, "密码更改成功", Toast.LENGTH_SHORT).show();
        }
        else{
            Log.i("TAG","4444");
            Toast.makeText(this, "用户名或密码输入错误", Toast.LENGTH_SHORT).show();
        }
    }}



